
function click_delete(checkName,param){
 var checkValue = getCheckValue(checkName);
 if(checkValue==""||checkValue=="undefine"||checkValue==null){
 	alert("请选择要删除的数据!");
 	return ;
 }else if(confirm('确定要删除所选的数据吗?')){
 	var targetUrl = actionName+'?actionMethod=delete&'+checkName+'='+checkValue;
 	if(param!=null&&param!='undefine'&&param.length>0){
 		targetUrl= targetUrl+'&'+param;
 	}
 	window.location.href=targetUrl;
 }
 return;
}

function getCheckValue(checkName){
 var checkValue="";
 var checkList = document.getElementsByName(checkName);
 for(var i=0;i<checkList.length;i++){
 	if(checkList[i].checked){
 		checkValue = checkList[i].value;
 		break;
 	}
 }
 return checkValue;
}

function cancelOther(obj){
	var checkList = document.getElementsByName(obj.name);
 	for(var i=0;i<checkList.length;i++){
 		if(checkList[i]!=obj){
 			checkList[i].checked=false;
 		}
	}
}

function queryData(actionName){
	document.forms.ec.action = actionName+(actionName.indexOf("?")>0?"&":"?")+"actionMethod=query";
	document.forms.ec.submit();
}
function editData(actionName){
	var checkName = getCheckName();
	if(checkName==''){
		return ;
	}
	var checkValue = getCheckValue(checkName);
	if(!checkValue){
		window.location.href = actionName+(actionName.indexOf("?")>0?"&":"?")+"actionMethod=add";
	}else{
		window.location.href = actionName+(actionName.indexOf("?")>0?"&":"?")+"actionMethod=edit&queryId="+checkValue;
	}
	
}
function deleteData(actionName){
	var checkName = getCheckName();
	if(checkName==''){
		return ;
	}
	var checkValue = getCheckValue(checkName);
	if(!checkValue){
		alert('请选择要删除的数据!');
		return;
	}
	if(confirm('确定要删除这些数据吗？')){
		document.forms.ec.action = actionName+(actionName.indexOf("?")>0?"&":"?")+"actionMethod=delete";
		document.forms.ec.submit();
	}
}

function assignData(actionName){
	var checkName = getCheckName();
	if(checkName==''){
		return ;
	}
	var checkValue = getCheckValue(checkName);
	if(checkValue==""||checkValue=="undefine"||checkValue==null){
 		alert("请选择一条被分配的数据!");
 		return ;
 	}
 	window.location.href = actionName+(actionName.indexOf("?")>0?"&":"?")+"actionMethod=assign&id="+checkValue;
}
function saveData(){
	document.forms[0].submit();
}

function checkAll(selectAllBoxObj){
	try{
		if(!selectAllBoxObj.type=='checkbox'||!selectAllBoxObj.name.endWith('_selector')){
			alert('必须是选择框。');
			return;
		}
	}catch(e){
		alert('选择框名称必须以XXX_selector命名。XXX是数据选择checkbox的名称！');
	}
	checkName = selectAllBoxObj.name;
	checkName = checkName.substring(0,checkName.indexOf('_'));
	var checkList = document.getElementsByName(checkName);
	for(var i=0;i<checkList.length;i++){
		checkList[i].checked = selectAllBoxObj.checked;
	}
}

function getCheckName(){
	if(document.forms.ec){
		var checkName = '';
		for(var i=0;i<document.forms.ec.elements.length;i++){
			if(document.forms.ec.elements[i].type=='checkbox'){
				if(document.forms.ec.elements[i].name.endWith('_selector')){
					checkName = document.forms.ec.elements[i].name;
					checkName = checkName.substring(0,checkName.indexOf('_'));
				}
			}
		}
		if(checkName==''){
			alert('警告!没有找到已经选择的数据');
		}
		return checkName;
	}else{
		alert('Can not find the extrem table in current view!');
		return '';
	}
}
String.prototype.endWith=function(oString){   
  var   reg=new   RegExp(oString+"$");   
  return   reg.test(this);   
 }
 
 String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function trimForm(formName){
 for(var i=0;i<document.forms[formName].elements.length;i++){
 	var formField = document.forms[formName].elements[i];
	var formFieldType=formField.type;
 	if(formFieldType=="text"||formFieldType=="hidden"||formFieldType=="select"||formFieldType=="textarea"){
		if(formField.value!=null&&formField.value.length>0){
			formField.value = formField.value.trim();
		}
 	}
 }
}

function openOamDialog(targetUrl,_width,_height){
	 var returnVal=window.showModalDialog('popWindow.do?targetUrl='+targetUrl,'','dialogwidth='+_width+'px; dialogheight='+_height+'px; status=no');
	 return returnVal;
	 
}
function getFilterPageVariable(formObj,pageSize,currentPage){
	var urlString = formObj.action;
	if(urlString.indexOf("pageSize=")>0){
		postion = urlString.indexOf("&",urlString.indexOf("pageSize="));
		if(postion<0){
			postion = urlString.length - 1;
		}
		urlString = urlString.substring(0,urlString.indexOf("pageSize="))+urlString.substring(postion + 1);
	}
	if(urlString.indexOf("currentPage=")>0){
		postion = urlString.indexOf("&",urlString.indexOf("currentPage="));
		if(postion<0){
			postion = urlString.length - 1;
		}
		urlString = urlString.substring(0,urlString.indexOf("currentPage="))+urlString.substring(postion + 1);
	}
	if(urlString.indexOf('?')<0){
		urlString += "?";
	}else if(urlString.substring(urlString.length -1)!='&'){
		urlString += "&";
	}
	formObj.action = urlString+"pageSize="+pageSize+"&currentPage="+currentPage;
}

function backMainPage(actionName){
	window.location.href=actionName;
}